<?php

/**
 * Short description for file
 *
 * PHP version 5
 *
 * LICENSE: GNU General Public License v3
 *
 * @category
 * @package
 * @author     Charly Poly <CharlyPoly@gmail.com>
 * @copyright  2009 Authentic Development Group
 * @license    GNU General Public License v3
 * @since      File available since Release 0.1.0
 */

class Logs {
    static $format = "FILE - LINE :  MESSAGE -- DATE / HEURE";
    static $name;
    static $data;

    public static function log($file, $format=FALSE)
    {
        self::$name = DATA_DIR.'logs'.DIR_SEP.$file.'.log';
        self::$format |= $format;
    }

    public static function set($name, $value) {
        self::$data[$name] = $value;
    }
    
    public static function record()
    {

        $message = "<<<Start \n";
        $message .= self::$format;
        foreach (self::$data as $s=>$r) {
            if (is_array($r)) {
                $message = str_replace($s, print_r($r, true), $message);
            } else {
                $message = str_replace($s, $r, $message);
            }
        }
        $message .= "\nEnd>>>\n";
        $fp = fopen(self::$name, 'a');
        $fr = fwrite($fp,$message, strlen($message));
        if (FALSE === $fr) {
            echo 'erreur ecriture !<br>';
        }
        fclose($fp);
    }



}
?>
